package com.huawei.hms.framework.network.restclient;

import com.huawei.hms.framework.network.restclient.SubmitAdapter.Factory;
import com.huawei.hms.framework.network.restclient.hwhttp.Request;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.concurrent.Executor;

public class ExecutorSubmitAdapterFactory extends Factory {
    private Executor executor;

    class ExecutorSubmit<T> implements Submit<T> {
        Executor executor;
        Submit<T> submit;

        ExecutorSubmit(Submit<T> submit, Executor executor) {
            this.submit = submit;
            this.executor = executor;
        }

        public Request request() throws IOException {
            return this.submit.request();
        }

        public Response<T> execute() throws IOException {
            return this.submit.execute();
        }

        public void cancel() {
            this.submit.cancel();
        }

        public boolean isExecuted() {
            return this.submit.isExecuted();
        }

        public boolean isCanceled() {
            return this.submit.isCanceled();
        }

        public Submit clone() {
            return new ExecutorSubmit(this.submit, this.executor);
        }

        public void enqueue(ResultCallback<T> resultCallback) {
            this.submit.enqueue(new 1(this, resultCallback));
        }
    }

    public ExecutorSubmitAdapterFactory(Executor executor) {
        this.executor = executor;
    }

    public SubmitAdapter<?, ?> get(Type type, Annotation[] annotationArr, RestClient restClient) {
        final Type submitResponseType = Utils.getSubmitResponseType(type);
        return new SubmitAdapter<Object, Object>() {
            public Type responseType() {
                return submitResponseType;
            }

            public Object adapt(Submit<Object> submit) {
                return new ExecutorSubmit(submit, ExecutorSubmitAdapterFactory.this.executor);
            }
        };
    }
}
